import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'
const ExpiresKey = 'Admin-Token-Expires'

/**
 * 获取token
 */
export function getToken(): string | undefined {
  return Cookies.get(TokenKey)
}

/**
 * 设置token
 * @param token 
 */
export function setToken(token: string) {
  Cookies.set(TokenKey, token)
}

/**
 * 移除token
 */
export function removeToken() {
  Cookies.remove(TokenKey)
}

/**
 * 获取token过期时间
 */
export function getTokenExpires(): number | undefined {
  const expires = Cookies.get(ExpiresKey)
  return expires ? parseInt(expires) : undefined
}

/**
 * 设置token过期时间
 * @param expires 
 */
export function setTokenExpires(expires: number) {
  Cookies.set(ExpiresKey, expires.toString())
}

/**
 * 移除token过期时间
 */
export function removeTokenExpires() {
  Cookies.remove(ExpiresKey)
}